package com.content.view.Frame.InfoTape
{
	import com.content.model.LoadedAssets.ConfigProxy;
	import com.content.view.AppMediator;
	import com.library.core.IDisposable;
	
	import flash.display.Sprite;
	import flash.events.DataEvent;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class InfoTape_Mediator extends Mediator implements IMediator, IDisposable
	{
		public static const NAME:String							= 'InfoTape_Mediator';
		
		private var _view:InfoTape;
		
		public function InfoTape_Mediator(viewComponent:Object=null)
		{
			super( NAME, viewComponent );
		}
		
		override public function onRegister():void
		{
			_view = new InfoTape(	P_Config.UI_InfoTape_Height,
									P_Config.UI_InfoTape_MarginLeft,
									P_Config.UI_InfoTape_MarginRight,
									P_Config.UI_CBarL1_Width + P_Config.UI_CBarL1_MarginLeft);
			
			ParentView.addChild( _view );
		}
		
		
		override public function listNotificationInterests():Array
		{
			return [
				InfoTape.SHOW,
				InfoTape.HIDE,
				App.RESIZE_SYS
			];
		}
		
		/* Event Handler
		* ---------------------------------------------------- */
		override public function handleNotification(notification:INotification):void
		{
			var name:String = notification.getName();
			var body:Object = notification.getBody();
			
			switch ( name )
			{
				case InfoTape.SHOW:
					_view.Show(body["delay"], body["duration"]);			
					break;
				
				case InfoTape.HIDE:
					_view.Hide();			
					break;
				
				case App.RESIZE_SYS:
					var sWidth:int = body["width"];
					var sHeight:int = body["height"];
					SetLayout(sWidth, sHeight);
					break;
			}
		}
		
		private function SetLayout(sWidth:int, sHeight:int):void{
			_view.SetLayout(sWidth, sHeight);	// 重画最下面的蓝色布纹填充
			_view.x = P_Config.UI_CBarL1_Width + P_Config.UI_CBarL1_MarginLeft + P_Config.UI_MainPanel_MarginLeft;
			_view.y = P_Config.UI_InfoTape_MarginTop;
		}
		
		/* Public Method
		 * ------------------------------------------------------ */
		public function InfoUpdate(xml:XML):void{
			_view.InfoUpdate(xml);
		}
		
		public function Dispose():void {
			_view.Dispose();
		}
		
		private function get ParentView():Sprite {return viewComponent as Sprite;}
		private function get P_Config():ConfigProxy	{return facade.retrieveProxy( ConfigProxy.NAME ) as ConfigProxy;}
	}
}